package com.lcq.study.pdf.jasper;

import com.lcq.study.pdf.dto.ModelTableSource;
import com.lcq.study.pdf.dto.PmYCDataDto;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperRunManager;
import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;

import java.util.*;

/**
 * @ClassName JasperReportTest
 * @Description
 * @Author lichuanqi
 * @Date 2022/6/24 10:07
 * @Version 1.0
 **/
public class JasperTableTest {
    public static void main(String[] args) throws JRException {
        HashMap<String, Object> params = new HashMap<>();
        params.put("outdoorConditions", "温度:-21.1°C 湿度:66% 风速:3 级 风向：WSW\n" +
                "PM2.5:132μg/m3 PM10:249μg/m3");

        String jasperFilePath = "C:/Users/86156/JaspersoftWorkspace/MyReports";
        String name = "BPAReport_8";
        String jasperFile = jasperFilePath + "/"+name+".jasper";
        String destFile = "D:/test/pdf/"+name+".pdf";
        ModelTableSource mts = new ModelTableSource();
        mts.setTableData(new JRBeanCollectionDataSource(getDataList()));
        List<ModelTableSource> mlist = new ArrayList<>();
        mlist.add(mts);
        JasperRunManager.runReportToPdfFile(jasperFile, destFile, params, new JRBeanCollectionDataSource(mlist));
    }

    public static List<PmYCDataDto> getDataList(){
        ArrayList<PmYCDataDto> list = new ArrayList<>();

        for (int i = 0; i < 30; i++) {
            PmYCDataDto pmYCDataDto = new PmYCDataDto();
            pmYCDataDto.setPm10yc("149.865106");
            pmYCDataDto.setPm205yc("79.473840");
            pmYCDataDto.setAirFilterClass("20.53%");
            pmYCDataDto.setRoomNum(""+i);
            pmYCDataDto.setWcmj("11.125");
            pmYCDataDto.setWcqmxdj("");
            pmYCDataDto.setRoomVolume("53.46");
            pmYCDataDto.setRoomUsage("办公室");
            list.add(pmYCDataDto);
        }


        return list;
    }
}
